import React, { Component } from 'react';
import PropTypes from 'prop-types'

class XiaojiejieItem extends Component {
    constructor(props) {
        super(props);
        this.state = {  }
        this.handleClik = this.handleClik.bind(this)
    }
    shouldComponentUpdate(nextProps,nextState){

        if(nextProps.content !== this.props.content){
            return true;
        }else{
            return false;
        }
    }
    render() { 
        console.log('child - render')
        return ( 
            //子组件通过super将父组件穿的值挂载到组件上，并通过this.props调用
            //子组件通过handleClik调用父组件的方法deleteItem
            <li onClick={this.handleClik}>{this.props.avname}-{this.props.content}</li>
         );
    }
    handleClik(){
      
        this.props.deleteItem(this.props.index)
    }
}
//校验父组件传过来的值
XiaojiejieItem.propTypes = {
    avname:PropTypes.string.isRequired,
    content:PropTypes.string,
    index:PropTypes.number,
    deleteItem:PropTypes.func
}
//默认值
XiaojiejieItem.defaultProps={
    avname:'成年人'
}
 
export default XiaojiejieItem;